package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.framework.config.ServerConfig;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.MemberCar;
import com.ruoyi.service.IMemberCarService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员车辆Controller
 * 
 * @author ruoyi
 * @date 2025-11-11
 */
@RestController
@RequestMapping("/parking/memberCar")
public class MemberCarController extends BaseController
{
    @Autowired
    private IMemberCarService memberCarService;
    @Autowired
    private ServerConfig serverConfig;

    /**
     * 查询会员车辆列表
     */
    @PreAuthorize("@ss.hasPermi('parking:memberCar:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberCar memberCar)
    {
        startPage();
        List<MemberCar> list = memberCarService.selectMemberCarList(memberCar);
        list.forEach(car -> {
            if (car.getDrivingLicensePhoto() != null) {
                car.setDrivingLicensePhoto(serverConfig.getUrl()  + car.getDrivingLicensePhoto());
            }
        });
        return getDataTable(list);
    }

    /**
     * 导出会员车辆列表
     */
    @PreAuthorize("@ss.hasPermi('parking:memberCar:export')")
    @Log(title = "会员车辆", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberCar memberCar)
    {
        List<MemberCar> list = memberCarService.selectMemberCarList(memberCar);
        ExcelUtil<MemberCar> util = new ExcelUtil<MemberCar>(MemberCar.class);
        util.exportExcel(response, list, "会员车辆数据");
    }

    /**
     * 获取会员车辆详细信息
     */
    @PreAuthorize("@ss.hasPermi('parking:memberCar:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        MemberCar memberCar = memberCarService.selectMemberCarById(id);
        memberCar.setAuthStatus("2");
        memberCar.setDrivingLicensePhoto(serverConfig.getUrl() + memberCar.getDrivingLicensePhoto());
        return success(memberCar);
    }

    /**
     * 新增会员车辆
     */
    @PreAuthorize("@ss.hasPermi('parking:memberCar:add')")
    @Log(title = "会员车辆", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberCar memberCar)
    {
        return toAjax(memberCarService.insertMemberCar(memberCar));
    }

    /**
     * 修改会员车辆
     */
    @PreAuthorize("@ss.hasPermi('parking:memberCar:edit')")
    @Log(title = "会员车辆", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberCar memberCar)
    {
        return toAjax(memberCarService.updateMemberCar(memberCar));
    }

    /**
     * 删除会员车辆
     */
    @PreAuthorize("@ss.hasPermi('parking:memberCar:remove')")
    @Log(title = "会员车辆", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(memberCarService.deleteMemberCarByIds(ids));
    }
}
